﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using FlatRedBall;
using FlatRedBall.Graphics;
using FlatRedBall.Math.Geometry;
using FlatRedBall.Input;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;

using FlatRedBall.Graphics.Animation;

using ROMAP.Utilities;

namespace ROMAP.Entities.Enemies
{
    public class Bullet : Enemy
    {
        private Sprite sprite;
        private float range;
        private float speed;
        private bool active;
        private string contentManagerName;

        public float Range
        {
            set { range = value; }
            get { return range; }
        }

        public float Speed
        {
            set { speed = value; }
            get { return speed; }
        }

        public bool Active
        {
            set { active = value; }
            get { return active; }
        }

        public Bullet(string contentManagerNam)
        {
            contentManagerName = contentManagerNam;
            Initialize(true);
        }

        protected virtual void Initialize(bool addToManagers)
        {
            base.Initialize();

            sprite = SpriteManager.AddSprite(@"Content/Obstacles/rock");

            sprite.AttachTo(this, false);
            sprite.PixelScale();
            sprite.ScaleX *= 0.1f;
            sprite.ScaleY *= 0.1f;

            sprite.RelativeZ = 0.5f;

            sprite.Visible = false;

            Collision = ShapeManager.AddAxisAlignedRectangle();
            Collision.AttachTo(this, false);
            Collision.ScaleX = sprite.ScaleX;
            Collision.ScaleY = sprite.ScaleY;
            Collision.Visible = false;

            active = false;
        }

        public void Activate()
        {
            active = true;
            sprite.Visible = true;
            this.RelativeVelocity.X = speed;
            this.X = this.RelativePosition.X;
        }

        public void Deactivate()
        {
            active = false;
            sprite.Visible = false;
            this.RelativeVelocity.X = 0.0f;
            this.RelativeX = this.xstart;
        }

        public override void Activity()
        {
            if (active)
            {
                if (Math.Abs(this.RelativeX - this.xstart) > range)
                {
                    this.Deactivate();
                }
            }
        }
    }
}
